﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pku.BookStore.IServices;
using System.ServiceModel.Activation;
using System.ServiceModel;

namespace Pku.BookStore.Services
{
    [Serializable]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true, ConcurrencyMode = ConcurrencyMode.Multiple)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class UserServices : IUserServices
    {
        /// <summary>
        /// 获取实例名
        /// </summary>
        private DAL.UserDAL userDal
        {
            get
            {
                return new DAL.UserDAL();
            }
        }

        /// <summary>
        /// 增加用户
        /// </summary>
        /// <param name="entity"></param>
        public int Add(Model.UserModel entity)
        {
            return userDal.Add(entity);
        }

        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="entity"></param>
        public bool Modify(Model.UserModel entity)
        {
            return userDal.Modify(entity);
        }

        /// <summary>
        /// 修改用户密码
        /// </summary>
        /// <param name="entity"></param>
        public bool ModifyPass(Model.UserModel entity)
        {
            return userDal.ModifyPass(entity);
        }

        /// <summary>
        /// 修改用户安全问题
        /// </summary>
        /// <param name="entity"></param>
        public bool ModifySafe(Model.UserModel entity)
        {
            return userDal.ModifySafe(entity);
        }

        /// <summary>
        /// 修改用户最后登录IP和时间
        /// </summary>
        /// <param name="entity"></param>
        public bool ModifyLogin(Model.UserModel entity)
        {
            return userDal.ModifyLogin(entity);
        }

        /// <summary>
        /// 搜索用户
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<Model.UserModel> Search(Model.UserParam param)
        {
            return userDal.Search(param);
        }

        /// <summary>
        /// 获取用户总数
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public int GetCount(Model.UserParam param)
        {
            return userDal.GetCount(param);
        }

        /// <summary>
        /// 返回用户信息
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public Model.UserModel GetEntityById(int userID)
        {
            return userDal.GetEntityById(userID);
        }

        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="Str">关键字</param>
        /// <param name="Type">0为用户名  1为邮箱</param>
        /// <returns></returns>
        public bool Exist(string Str, int Type)
        {
            return userDal.Exist(Str, Type);
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Model.UserModel Login(Model.UserModel entity)
        {
            return userDal.Login(entity);
        }
    }
}
